import axios from 'axios'
import ElementUI from 'element-ui'
import router from './router'
import store from './store'


//配置异步之前添加URL
axios.defaults.baseURL="http://localhost:8081"


//配置前置拦截
axios.interceptors.request.use(config =>{
    return config
})

axios.interceptors.response.use(response =>{
  let res = response.data

    if (res.code === 200){
        return response
    }else {
        ElementUI.Message.error(res.msg,{duration : 1000})
        return Promise.reject(response.data.msg)
    }
}

    //状态码为200不用error
    /*error => {

        if(error.response.data){
            error.message=error.response.data.msg
        }

        if(error.response.status === 400){
            store.commit("REMOVE_INFO")
            router.push("/login")
        }

        if(error.response.status === 401){
            store.commit("REMOVE_INFO")
            router.push("/login")
        }

        ElementUI.Message.error(error.message,{duration : 1000})
        return Promise.reject(error)

    }*/
)